package com.lbt.eduservice.controller.front;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lbt.commonuntils.R;
import com.lbt.eduservice.entity.EduCourse;
import com.lbt.eduservice.entity.EduTeacher;
import com.lbt.eduservice.service.EduCourseService;
import com.lbt.eduservice.service.EduTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(description = "首页面管理")
//@CrossOrigin
@RestController
@RequestMapping("/eduservice/indexfront")
public class IndexFrontController {
    @Autowired
    EduCourseService courseService;
    @Autowired
    EduTeacherService teacherService;
    //查询八个热门课程  四个名师显示在首页面
    @ApiOperation(value = "查询八个热门课程  四个名师显示在首页面")
    @GetMapping("/index")
    public R index(){
        QueryWrapper<EduCourse>courseWrapper=new QueryWrapper<>();
        courseWrapper.last("limit 8");
        courseWrapper.orderByDesc("view_count");
        List<EduCourse> courseList = courseService.list(courseWrapper);
        QueryWrapper<EduTeacher>teacherWrapper=new QueryWrapper<>();
        teacherWrapper.last("limit 4");
        teacherWrapper.orderByDesc("level");
        List<EduTeacher> teacherList = teacherService.list(teacherWrapper);
        return R.ok().data("eduList",courseList).data("teacherList",teacherList);

    }



}
